home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCTXT.ZIP / CHAP1.TXT next >
Text File  |  1988-01-15  |  6KB  |  125 lines

  1.  
  2.                  CHAPTER 1 - What is a computer program?
  3.  
  4.  
  5.              If you are a complete novice to computers you will find
  6.         the  information  in this chapter useful.  If  however,  you
  7.         have   had  some  experience  with  programming,   you   can
  8.         completely  ignore  this chapter.  It will deal with  a  few
  9.         fundamentals  of  computers in general  and  will  introduce
  10.         nothing that is specific to Pascal.
  11.  
  12.                          WHAT IS A COMPUTER PROGRAM?
  13.  
  14.              A computer is nothing but a very dumb machine that  has
  15.         the ability to perform mathematical operations very  rapidly
  16.         and  very accurately, but it can do nothing without the  aid
  17.         of  a  program written by a human being.  Moreover,  if  the
  18.         human  being  writes  a program that turns  good  data  into
  19.         garbage,  the  computer  will  very  obediently,  and   very
  20.         rapidly, turn the good data into garbage.  It is possible to
  21.         write  a  computer program with one small error in  it  that
  22.         will  do that very thing, and in some cases appearing to  be
  23.         generating  good data.  It is up to the human programmer  to
  24.         design a program to achieve the desired results.
  25.  
  26.              A  computer  program  is simply a  "recipe"  which  the
  27.         computer  will use on the input data to derive  the  desired
  28.         output data.  It is similar to the recipe for baking a cake.
  29.         The  input data is comparable to the ingredients,  including
  30.         the heat supplied by the oven.  The program is comparable to
  31.         the recipe instructions to mix, stir, wait, heat, cool,  and
  32.         all  other  possible  operations on  the  ingredients.   The
  33.         output of the computer program can be compared to the  final
  34.         cake  sitting on the counter ready to be cut and served.   A
  35.         computer  program  then is composed of two parts,  the  data
  36.         upon  which  the  program operates,  and  the  program  that
  37.         operates on the data.  The data and program are  inseparable
  38.         as implied by the last sentence.
  39.  
  40.                              WHAT ARE CONSTANTS?
  41.  
  42.              Nearly any computer program requires some numbers  that
  43.         never  change throughout the program.  They can  be  defined
  44.         once and used as often as needed during the operation of the
  45.         program.   To  return to the recipe analogy, once  you  have
  46.         defined  how  big  a tablespoon is, you  can  use  the  same
  47.         tablespoon without regard to what you are measuring with it.
  48.         When writing a computer program, you can define the value of
  49.         PI  =  3.141592, and continue to use it  wherever  it  makes
  50.         sense knowing that it is available, and correct.
  51.  
  52.                              WHAT ARE VARIABLES?
  53.  
  54.              In addition to constants, nearly every computer program
  55.         uses  some  numbers  that change  in  value  throughout  the
  56.  
  57.  
  58.                                 Page 5
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.                  CHAPTER 1 - What is a computer program?
  69.  
  70.  
  71.         program.  They can be defined as variables, then changed  to
  72.         any  values that make sense to the proper operation  of  the
  73.         program.   An  example would be the number of  eggs  in  the
  74.         above  recipe.  If a single layer of cake required  2  eggs,
  75.         then  a triple layer cake would require 6 eggs.  The  number
  76.         of eggs would therefore be a variable.
  77.  
  78.                   HOW DO WE DEFINE CONSTANTS OR VARIABLES?
  79.  
  80.              All  constants and variables have a name and  a  value.
  81.         In  the last example, the name of the variable  was  "eggs",
  82.         and the value was either 2 or 6 depending on when we  looked
  83.         at the stored data.  In a computer program the constants and
  84.         variables  are  given names in much the same  manner,  after
  85.         which  they  can store any value within the  defined  range.
  86.         Any  computer  programming  language has a  means  by  which
  87.         constants  or variables can be first named, then assigned  a
  88.         value.   The  means for doing this in Pascal will  be  given
  89.         throughout the remainder of this tutorial.
  90.  
  91.                         WHAT IS SO GOOD ABOUT PASCAL?
  92.  
  93.              Some computer languages allow the programmer to  define
  94.         constants and variables in a very haphazard manner and  then
  95.         combine data in an even more haphazard manner.  For example,
  96.         if you added the number of eggs, in the above recipe, to the
  97.         number  of  cups  of  flour, you  would  arrive  a  a  valid
  98.         mathematical  addition,  but a totally  meaningless  number.
  99.         Some  programming languages would allow you to do just  such
  100.         an addition and obediently print out the meaningless answer.
  101.         Since  Pascal  requires  you to set up  your  constants  and
  102.         variables in a very precise manner, the possibility of  such
  103.         a  meaningless answer is minimized.  A well  written  Pascal
  104.         program has many cross checks to minimize the possibility of
  105.         a completely scrambled and meaningless output.
  106.  
  107.              Notice  however,  in the last statement, that  a  "well
  108.         written"  Pascal program was under discussion.  It is  still
  109.         up to the programmer to define the data structure in such  a
  110.         way that the program can prevent garbage generation.  In the
  111.         end,  the program will be no better than the  analysis  that
  112.         went into the program design.
  113.  
  114.              If  you are a novice programmer, do not be  intimidated
  115.         by any of the above statements.  Pascal is a well  designed,
  116.         useful tool that has been used successfully by many computer
  117.         novices and professionals.  With these few warnings, you are
  118.         ready to begin.
  119.  
  120.  
  121.  
  122.  
  123.  
  124.                                 Page 6
  125.